  1 #coding:utf-8
  2 from django.shortcuts import render
  3 
  4 # Create your views here.
  5 
  6 #define the user action and then
  7 
  8 from django.db.models import Q
  9 from django.db import models
 10 from django.shortcuts import  render  #render_to_respoonse
 11 from http import HttpResponse
 12 #import models each instance into your views function
 13 from models import Address,Person,Product
 14 #add the models.py Model into your view.py Model
 15 
 16 def search(request,mode):                                                   
 17     query = request.GET('q','')
 18     if query :                                                              
 19         qset = (                                                            
 20             Q(Address.end_address = query),                                 
 21             Q(Product.pro_name = query),                                    
 22        )                                                                    
 23                                                                             
 24         result = Address.objects.all()                                      
 25         #here return the search result and let the other functions know it! 
 26     else:                                                                   
 27         result = []                                                         
 28                                                                             
 29     return HttpResponse('/home/CrowdSourcing/delivery/template/base.html',  
 30                     {'result':result,"query":query }                        
 31                  )                                                          
 32                                                                             
 33 #@accept_and_submit_mission                                                 
 34 def choice_and_accept(request):                                             
 35     #find the fixed  search result and accept this submission               
 36                                                               